const { readFileSync, existsSync } = require('node:fs')
const { ipcMain } = require('electron')
const url = process.env.NODE_ENV != 'development' ? `${process.cwd()}/resources/config.json` : `${process.cwd()}/config.json`
let config = null
try {
  config = existsSync(url) ? JSON.parse(readFileSync(url).toString()) : null
} catch (error) {
  console.error('Error parsing JSON to config:', error.message)
}

ipcMain.handle('on-config-event', (e) => {
    return config
})

module.exports = config